########################################################################
#  Wiizard - A Wii games manager
#  Copyright (C) 2023  CYBERDEViL
#
#  This file is part of Wiizard.
#
#  Wiizard is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  Wiizard is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
########################################################################


from PyQt5.QtWidgets import (
  QDialog,
  QGridLayout,
  QLabel
)

from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt

import pywwt

from wiizard.version import __version__ as WiizardVersion
from wiizard.images import AppResources
from wiizard.translations import _


class AboutDialog(QDialog):
  def __init__(self, parent=None):
    QDialog.__init__(self, parent=parent)

    self.setWindowTitle(_("About Wiizard"))

    layout = QGridLayout(self)

    logo = QLabel(self)
    logo.setPixmap(QPixmap(AppResources.getImagePath("wiizard_logo.png")))

    title = QLabel("<h1>Wiizard</h1>", self)
    summary = QLabel(_("<i>A Wii games manager</i>"), self)

    versionLabel = QLabel(_("<b>Version:</b>"), self)
    versionValue = QLabel(WiizardVersion)
    versionValue.setTextInteractionFlags(Qt.TextSelectableByMouse)

    licenseLabel = QLabel(_("<b>License:</b>"), self)
    licenseValue = QLabel("<a href=\"https://www.gnu.org/licenses/licenses"
                          ".html#GPL\">GPL3</a>")

    pywwtVersionLabel = QLabel("<b>PyWWT:</b>", self)
    pywwtVersionValue = QLabel("{} r{} arch: {}".format(*pywwt.version().values()))
    pywwtVersionValue.setTextInteractionFlags(Qt.TextSelectableByMouse)

    urlLabel = QLabel("<a href=\"https://notabug.org/CYBERDEViL/Wiizard\">"
                      "https://notabug.org/CYBERDEViL/Wiizard</a>", self)

    layout.addWidget(logo             , 0, 0, 1, 3, Qt.AlignHCenter)
    layout.addWidget(title            , 1, 0, 1, 3, Qt.AlignHCenter)
    layout.addWidget(summary          , 2, 0, 1, 3, Qt.AlignHCenter)
    layout.addWidget(versionLabel     , 3, 0, 1, 1, Qt.AlignRight)
    layout.addWidget(versionValue     , 3, 1, 1, 2)
    layout.addWidget(licenseLabel     , 4, 0, 1, 1, Qt.AlignRight)
    layout.addWidget(licenseValue     , 4, 1, 1, 2)
    layout.addWidget(pywwtVersionLabel, 5, 0, 1, 1, Qt.AlignRight)
    layout.addWidget(pywwtVersionValue, 5, 1, 1, 2)
    layout.addWidget(urlLabel         , 6, 0, 1, 3, Qt.AlignHCenter)
